home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
4_0
/
LISTMANA
/
__TESTER
/
NORMALLI.C
< prev
next >
Wrap
Text File
|
1989-06-25
|
9KB
|
386 lines
/**** */
/**** List Testing Code version 1.0 (beta) */
/**** */
/**** All portions of this source code are the property of Jack */
/**** Herrington. I, Jack Herrington, give you permission to use */
/**** use or alter the code in any way that pleases you. You must */
/**** however return by whatever means avaliable any improvements */
/**** you believe significant to Jack Herrington, accepting that */
/**** these improvements might be contained in later releases of */
/**** the code. I also grant you permission to remove this header */
/**** from any file you are WORKING on, as long as you put it back */
/**** when you're stopped WORKING on it. */
/**** */
/**** Jack Herrington: University Of Miami, Biomedical Computing */
/**** 1600 N.W. 10th Ave. (R-53) */
/**** (305) 547-6538 */
/**** */
/****/
/**** Normal List Handler */
/****/
#include "ListManager.h"
#include "Tester.h"
#include "NormalList.h"
/****/
/**** Normal List main dispersion routine */
/****/
void NormalListHandler(mess,data)
int mess;
unsigned char *data;
{
switch(mess)
{
case MESS_NEW: NormalListHandlerNew(); break;
case MESS_HIT: NormalListHandlerHit((int *)data); break;
case MESS_CLOSE: NormalListHandlerClose(); break;
case MESS_ACTIVATE: NormalListHandlerActivate(1); break;
case MESS_DEACTIVATE: NormalListHandlerActivate(0); break;
case MESS_KEY: NormalListHandlerKey((char)*data); break;
}
}
/****/
/**** Respond to a new message */
/****/
void NormalListHandlerNew()
{
NormalWindowInfo *nwi;
/**** Create the dialog */
if ( TesterDialogNew(1000,CurHandler) == (-1) ) return;
SetPort(Windows[CurWindow].window);
/**** Allocate the window record */
TesterAllocateWindowData((long)sizeof(NormalWindowInfo));
TesterLockWindowInfo();
nwi = (NormalWindowInfo *)TesterGetWindowInfo();
/**** Setup the window */
NormalListHandlerSetupList(nwi);
/**** Unlock the window information and leave */
TesterUnLockWindowInfo();
}
/****/
/**** Setup the list */
/****/
void NormalListHandlerSetupList(nwi)
NormalWindowInfo *nwi;
{
Handle item;
Point cellSize,cell;
Rect box,dBox;
char charTmp[255];
int type,x,y;
/**** Get the box for the list */
GetDItem(Windows[CurWindow].window,ListBox,&type,&item,&box);
SetDItem(Windows[CurWindow].window,ListBox,type,
NormalListHandlerUpdate,&box);
/**** Create the data bounds */
dBox.left = 0; dBox.right = MAX_X;
dBox.top = 0; dBox.bottom = MAX_Y;
cellSize.h = 80; cellSize.v = 12;
/**** Create the list */
nwi->nlh = ListNew(&box,&dBox,cellSize,0,
Windows[CurWindow].window,0,0,1,1);
/**** Setup framing parameters */
nwi->frameOff = 20;
ListSetFrameWidth(nwi->frameOff*2,nwi->frameOff,nwi->nlh);
ListSetFrameDrawer(NormalListHandlerDrawFrame,nwi->nlh);
/**** Setup global cell definitions */
ListSetGlobalBox((ListBottom|ListRight|ListGray),nwi->nlh);
ListSetGlobalFont(times,12,0,nwi->nlh);
ListSetScrollMethod(incMethod,nwi->nlh);
/**** Redo the row and column widths */
for(y=0;y<MAX_Y;y++)ListSetRowWidth(y,15+(y*2),nwi->nlh);
for(y=0;y<MAX_X;y++)ListSetColumnWidth(y,80+(y*5),nwi->nlh);
/**** Set the bottom and right addative */
ListSetAddative(20,20,nwi->nlh);
/**** Set the cells */
for(y=0;y<MAX_Y;y++)
{
for(x=0;x<MAX_X;x++)
{
(void)sprintf(charTmp,"%d - %d",x+1,y+1);
cell.h = x;
cell.v = y;
#ifdef UseTextBox
ListSetHandler(TextBoxHandler,cell,nwi->nlh);
#else
(void)CtoPstr(charTmp);
#endif
ListSetCell((unsigned char *)charTmp,strlen(charTmp),cell,nwi->nlh);
}
}
/**** Setup the flags */
ListSetEhancedFlags((NoAutoEditingSize),nwi->nlh);
ListDoDraw(TRUE,nwi->nlh);
/**** Setup the sizeing area */
nwi->sizeArea.top = 15;
nwi->sizeArea.bottom = 100;
nwi->sizeArea.left = 30;
nwi->sizeArea.right = 150;
/**** Hilite the buttons correctly */
NormalListHandlerHilite(nwi);
}
/****/
/**** Draw the list */
/****/
pascal void NormalListHandlerUpdate(Window,ItemNumber)
WindowPtr Window;
int ItemNumber;
{
NormalWindowInfo *nwi;
/**** Lock the window information and update */
TesterLockWindowInfoWindow(Window);
nwi = (NormalWindowInfo *)TesterGetWindowInfoIndirect(Window);
ListUpdateWhole(nwi->nlh);
TesterUnLockWindowInfoWindow(Window);
}
/****/
/**** Send a key to the list */
/****/
void NormalListHandlerKey(key)
char key;
{
NormalWindowInfo *nwi;
/**** Lock the window information and update */
TesterLockWindowInfo();
nwi = (NormalWindowInfo *)TesterGetWindowInfo();
ListEditKey(key,nwi->nlh);
TesterUnLockWindowInfo();
}
/****/
/**** Hit in the window */
/****/
void NormalListHandlerHit(hit)
int *hit;
{
NormalWindowInfo *nwi;
Point cell,lpt;
Rect sizeArea;
int part;
/**** Lock the window information */
TesterLockWindowInfo();
nwi = (NormalWindowInfo *)TesterGetWindowInfo();
SetPort(Windows[CurWindow].window);
/**** Disperse according to dialog hit */
if ( *hit == ListBox )
{
GetMouse(&lpt);
part = ListPart(lpt,&cell,nwi->nlh);
switch(part)
{
case inTextEditCell:
ListEditClick(lpt,(Boolean)0,nwi->nlh);
break;
case inHorizSizer:
case inVertSizer:
ListCellSizer(nwi->sizeArea,part,cell,nwi->nlh);
break;
case inHorizScroll:
case inVertScroll:
case inCell:
if ( ListCickEnhanced(lpt,0,nwi->nlh,ListSingleDrag) == 1 )
{
ListEditStart(ListLastClick(nwi->nlh),nwi->nlh);
}
break;
}
if ( part == inCell ) NormalListHandlerHilite(nwi);
}
else if ( *hit == AddColumn )
{
cell.h = cell.v = 0;
ListGetSelect(TRUE,&cell,nwi->nlh);
ListAddColumn(1,cell.h,nwi->nlh);
NormalListHandlerHilite(nwi);
}
else if ( *hit == DelColumn )
{
cell.h = cell.v = 0;
ListGetSelect(TRUE,&cell,nwi->nlh);
ListCleanList(nwi->nlh);
ListDelColumn(1,cell.h,nwi->nlh);
NormalListHandlerHilite(nwi);
}
else if ( *hit == AddRow )
{
cell.h = cell.v = 0;
ListGetSelect(TRUE,&cell,nwi->nlh);
ListAddRow(1,cell.v,nwi->nlh);
NormalListHandlerHilite(nwi);
}
else if ( *hit == DelRow )
{
cell.h = cell.v = 0;
ListGetSelect(TRUE,&cell,nwi->nlh);
ListCleanList(nwi->nlh);
ListDelRow(1,cell.v,nwi->nlh);
NormalListHandlerHilite(nwi);
}
else if ( *hit == Frame )
{
if ( nwi->frameOff == 20 ) nwi->frameOff = 0;
else nwi->frameOff = 20;
ListSetFrameWidth(nwi->frameOff*2,nwi->frameOff,nwi->nlh);
}
else if ( *hit == CleanList )
{
ListCleanList(nwi->nlh);
NormalListHandlerHilite(nwi);
}
else if ( *hit == CellSizeButton )
{
cell.h = 80;
cell.v = 15;
ListCellSize(cell,nwi->nlh);
}
else if ( *hit == AutoScrollButton ) ListAutoScroll(nwi->nlh);
/**** Unlock the window information */
TesterUnLockWindowInfo();
}
/****/
/**** Change the hiliting on the buttons */
/****/
void NormalListHandlerHilite(nwi)
NormalWindowInfo *nwi;
{
Handle item;
Point cell;
Rect box;
int type,stat;
/**** Find if there is an active cell */
cell.h = cell.v = 0;
if ( ListGetSelect(TRUE,&cell,nwi->nlh) == TRUE ) stat = 0;
else stat = 255;
/**** Hilite the buttons */
GetDItem(Windows[CurWindow].window,AddColumn,&type,&item,&box);
HiliteControl((ControlHandle)item,stat);
GetDItem(Windows[CurWindow].window,DelColumn,&type,&item,&box);
HiliteControl((ControlHandle)item,stat);
GetDItem(Windows[CurWindow].window,AddRow,&type,&item,&box);
HiliteControl((ControlHandle)item,stat);
GetDItem(Windows[CurWindow].window,DelRow,&type,&item,&box);
HiliteControl((ControlHandle)item,stat);
}
/****/
/**** Draw the frame title */
/****/
void NormalListHandlerDrawFrame(message,visBox,cell)
int message;
Rect *visBox;
int cell;
{
char charTmp[255];
int half,width;
/**** Draw the message into the frame */
if ( message == VertCell )
{
MoveTo(visBox->left+2,visBox->bottom-2);
NumToString((long)cell+1,charTmp);
DrawString(charTmp);
DrawChar('.');
}
else if ( cell < MAX_X )
{
width = StringWidth(Titles[cell]) / 2;
half = visBox->left + ( ( visBox->right - visBox->left ) / 2 );
MoveTo(half-width,visBox->bottom-2);
DrawString(Titles[cell]);
}
}
/****/
/**** Activate or DeActivate the list */
/****/
void NormalListHandlerActivate(act)
int act;
{
NormalWindowInfo *nwi;
TesterLockWindowInfo();
nwi = (NormalWindowInfo *)TesterGetWindowInfo();
ListActivate(act,nwi->nlh);
TesterUnLockWindowInfo();
}
/****/
/**** Close up the window */
/****/
void NormalListHandlerClose()
{
NormalWindowInfo *nwi;
TesterLockWindowInfo();
nwi = (NormalWindowInfo *)TesterGetWindowInfo();
ListDispose(nwi->nlh);
TesterUnLockWindowInfo();
TesterKillWindow(CurWindow);
}